<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>4-04 截取图片</title>
</head>
<body>
  <canvas id="c" width="500" height="500" style="border: 1px solid #ccc;"></canvas>

  <script>
    const context = document.getElementById('c')
    const ctx = context.getContext('2d')

    const image = new Image()
    image.src = '../images/dog.jpg'

    image.onload = () => {
      ctx.drawImage(image, 0, 0, 100, 100, 30, 30, 200, 200)
    }
  </script>
</body>
</html>